function [share_d, profit_d] = get_share_f(x, N_d, alpha_price, alpha_population, population_log_d, alpha_distance, distance_d, alpha_1, Y_d, nn, Y_market, prod_pct_d, m1_d, m0_d, N_k)

price_d = x(1:N_d, 1); 
q_d = x((N_d + 1):(2*N_d), 1); 

delta_d = q_d + log(price_d)*alpha_price + alpha_population*population_log_d + alpha_distance*distance_d;
delta_market_counter = delta_d;
expmeanval_market_counter = exp(delta_market_counter);

expmu_d = exp(log(price_d)*alpha_1*Y_d);
expmu_market_counter = expmu_d;

marketForProducts_counter = ones(size(delta_market_counter,1), 1);
sharesum_market_counter = sparse(zeros(1,size(delta_market_counter,1)));
sharesum_market_counter(1,:) = 1;
oo = ones(1,nn);   
numer_counter = (expmeanval_market_counter*oo ).*expmu_market_counter;        
sum1 = sharesum_market_counter*numer_counter;
sum11 = 1./(0+sum1);                      
denom1 = sum11(marketForProducts_counter,:);    
simShare_counter = numer_counter.*denom1;              
EstShare_counter = mean(simShare_counter,2); 
share_d = EstShare_counter;

mc = exp(m0_d .* (q_d(1:N_k, 1) .^ m1_d));

profit_d = ((price_d - mc) ./ price_d) .* share_d;

end

